package com.ruoyi.web.controller.societies;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ClubActivities;
import com.ruoyi.system.service.IClubActivitiesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社团活动Controller
 * 
 * @author ruoyi
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/system/activities")
public class ClubActivitiesController extends BaseController
{
    @Autowired
    private IClubActivitiesService clubActivitiesService;

    /**
     * 查询社团活动列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ClubActivities clubActivities)
    {
        startPage();
        List<ClubActivities> list = clubActivitiesService.selectClubActivitiesList(clubActivities);
        return getDataTable(list);
    }

    /**
     * 根据社团ID查询活动列表
     */
    @GetMapping("/club/{clubId}")
    public AjaxResult listByClub(@PathVariable("clubId") Long clubId)
    {
        List<ClubActivities> list = clubActivitiesService.selectClubActivitiesByClubId(clubId);
        return success(list);
    }

    /**
     * 查询即将开始的活动
     */
    @GetMapping("/upcoming")
    public AjaxResult upcomingActivities(@RequestParam(defaultValue = "10") Integer limit)
    {
        List<ClubActivities> list = clubActivitiesService.selectUpcomingActivities(limit);
        return success(list);
    }

    /**
     * 查询用户参与的活动
     */
    @GetMapping("/my-participated")
    public AjaxResult myParticipatedActivities()
    {
        Long userId = SecurityUtils.getUserId();
        List<ClubActivities> list = clubActivitiesService.selectUserParticipatedActivities(userId);
        return success(list);
    }

    /**
     * 导出社团活动列表
     */
    @Log(title = "社团活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClubActivities clubActivities)
    {
        List<ClubActivities> list = clubActivitiesService.selectClubActivitiesList(clubActivities);
        ExcelUtil<ClubActivities> util = new ExcelUtil<ClubActivities>(ClubActivities.class);
        util.exportExcel(response, list, "社团活动数据");
    }

    /**
     * 获取社团活动详细信息
     */
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(clubActivitiesService.selectClubActivitiesByActivityId(activityId));
    }

    /**
     * 新增社团活动
     */
    @Log(title = "社团活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClubActivities clubActivities)
    {
        return toAjax(clubActivitiesService.insertClubActivities(clubActivities));
    }

    /**
     * 修改社团活动
     */
    @Log(title = "社团活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClubActivities clubActivities)
    {
        return toAjax(clubActivitiesService.updateClubActivities(clubActivities));
    }

    /**
     * 删除社团活动
     */
    @Log(title = "社团活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(clubActivitiesService.deleteClubActivitiesByActivityIds(activityIds));
    }
}
